﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>商品销售详情</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script type="text/javascript" src="../js/dataTable.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script> 
<script type="text/javascript" src="../js/find.js"></script>
<script type="text/javascript" src="../js/qmsk-1.0.js"></script>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<script type="text/javascript" >
/**
 * 入口，和服务器的通信从此开始
 */
$(function() {
	refreshInput($(".serWrapper"));
	initShopSelecter();
	$('.doubledate').kuiDate({
		className : 'doubledate',
		isDisabled : "0" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
	});
	$('.doubledate1').kuiDate({
		className : 'doubledate1',
		isDisabled : "0" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
	});
	
	

	qmsk.initSelect({
		url : '../goodsTypeMed/find/opt/0/10',
		id : 'medId',
		heads : ['id', 'name'],
		defaults : {
			key : '请选择商品类型',
			value : ' '
		}
	});
	
	initGoodsTypeSelect();
});

function initGoodsTypeSelect(){
	$("#goodsTypeIsChoosed").removeAttr("checked");
	$("#medId").attr("disabled", "disabled");
	
	$("#goodsTypeIsChoosed").bind("click", function() {
		var checked = $(this).attr("checked");
		if (checked) {
			$("#medId").removeAttr("disabled");
		} else {
			$("#medId").attr("disabled", "disabled");
			$("#medId").empty();
		}
	});
}

/**
 * 为查找做准备，这里主要是生成查询条件对象
 */
function toSearch() {
	$("#goodsInfo").empty();
	$("#sum").empty();
	var shopId = $('#shopID').val();
	var startDate = $('#startDate').val();
	var endDate = $('#endDate').val();
	var medId = $('#medId').val();
	var billNo = $('#billNo').val();
	var memberCard = $('#memberCard').val();
	new Pagination({
		url : '../saleBill/find/sale/goodsTypeInfo/',
		data : {
			shopId : shopId,
			startDate : startDate,
			endDate : endDate,
			medId : medId,
			memberCard : memberCard,
			billNo : billNo
		},
		success : printDataToPage,
		pageSize : 10
	});
}

function downRescouse(){
	$("#goodsInfo").empty();
	$("#sum").empty();
	var shopId = $('#shopID').val();
	var startDate = $('#startDate').val();
	var endDate = $('#endDate').val();
	var medId = $('#medId').val();
	var billNo = $('#billNo').val();
	var param={
			shopId : shopId,
			startDate : startDate,
			endDate : endDate,
			medId : medId,
			billNo : billNo
		}
	window.location.href='../saleBill/export/csv?'+$.param(param)
}

function printDataToPage(message){
	var oldBillNo = null;
	dataTable({
		tbodyId : 'goodsInfo',
		heads : ["billNo", "CardNo", "ReciveDate", "goodsName", "SaleNums", "SalePrice", "saleMoney", "FactAmt" ,"Reciver","STATUS"],
		rst : message,
		sup : {
			id : "sup",
			template : "共 [index] 条"
		},
		handler : [{
			col : 9,
			f : detail
		}]
	});
	findGoodsTypeSum();
}

function detail(heads,rows){
	var staName=heads;
	if(IsNotEmpty(staName)){
		if(staName == 0){
			staName = "开单";
		}else if (staName == 1){
			staName = "结算";
		}else if (staName == 2){
			staName = "付款";
		}
	}
	return staName;
}

/**
 * 累计消费总和
 */
function findGoodsTypeSum(){
	var shopId = $('#shopID').val();
	var startDate = $('#startDate').val();
	var endDate = $('#endDate').val();
	var medId = $('#medId').val();
	var billNo = $('#billNo').val();
	var memberCard = $('#memberCard').val();
/* 	new Pagination({
		url : '../find/sale/goodsTypeInfo/sum',
		data : {
			shopId : shopId,
			startDate : startDate,
			endDate : endDate,
			medId : medId,
			billNo : billNo
		},
		success : printDataToPageSum,
		pageSize : 10
	}); */
	var rst = _findInfo("../saleBill/find/sale/goodsTypeInfo/sum",{
		"shopId" : shopId,
		"startDate" : startDate,
		"endDate" : endDate,
		"medId" : medId,
		"memberCard" : memberCard,
		"billNo" : billNo
	});
	
	if(IsNotEmpty(rst)){
		var sum = rst.result.data[0];
		if(sum > 0){
			$("#sum").html("总计消费金额:"+sum+"元");
		}else{
			$("#sum").html("");
		}
	}
}


/**
 * 初始化店面选择器
 */
function initShopSelecter() {
	refreshInput($(".serWrapper"));
	$("#shopID").attr("disabled", "disabled");

	$("#shopIsChoosed").bind("click", function() {
		var checked = $(this).attr("checked");
		if (checked) {
			$("#shopID").removeAttr("disabled");
		} else {
			$("#shopID").attr("disabled", "disabled");
			$("#shopID").empty();
		}
	});
}

</script>
</head>

<body>
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">商品销售分类明细</div>
    <div class="member_search">
      <p><span>
        <input type="checkbox" id="shopIsChoosed" style="width:auto;height:auto;border:none;">
        店面：</span>
 		<select id="shopID"  class="shopName" onclick="openShopListPanel(this)" style="height: 20px;"></select>
        <span>付款起始日期：</span>
        <input type="text" readonly class="doubledate ipticon"  id="startDate"/>
        <span>付款截止时间：</span>
        <input type="text" readonly class="doubledate1 ipticon" id="endDate"/>
      </p>
      <p>
        <span><input type="checkbox" id="goodsTypeIsChoosed" style="width:auto;height:auto;border:none;">商品类型：</span>
       	<select id="medId"  class="shopName"  style="height: 20px;"></select>
      <span>单号</span>
      <input type="text" id="billNo" class="absoluteTxt" >
      <span>会员卡号</span>
      <input type="text" id="memberCard" class="absoluteTxt" >
      <input type="button" value="查询" class="btn" onclick="toSearch()">
      </p>
    </div>
    <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
      <caption>
      <strong>商品销售详情列表 <span id="sup">共0条</span></strong> <a href="javascript:void(0)" onclick="downRescouse()">导出数据</a>
      </caption>
      <thead>
        <tr>
          <th>单号</th>
          <th>会员卡号</th>
          <th>收款时间</th>
          <th>服务信息</th>
          <th>销售次数</th>
          <th>销售单价</th>
          <th>小计</th>
          <th>实收款</th>
          <th>收款人</th>
          <th>状态</th>
        </tr>
      </thead>
      <tbody id="goodsInfo">
      
      </tbody>
    </table>
     <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="sum" style="float: left;"></div>
    <div id="pager" class="pager"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
</script>
</body>
<!-- InstanceEnd -->
</html>
